{% if is_paginated %}
    <nav aria-label="Topics pagination" class="mb-4">
        <ul class="pagination">
            {% if page_obj.has_previous %}
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a>
                </li>
            {% else %}
                <li class="page-item disabled">
                    <span class="page-link">上一页</span>
                </li>
            {% endif %}

            {% for page_num in paginator.page_range %}
                {% if page_obj.number == page_num %}
                    <li class="page-item active">
                        <span class="page-link">
                            {{ page_num }}
                            <span class="sr-only">(当前页)</span>
                        </span>
                    </li>
                {% elif page_num > page_obj.number|add:'-3' and page_num < page_obj.number|add:'3' %}
                    <li class="page-item">
                        <a class="page-link" href="?page={{ page_num }}">{{ page_num }}</a>
                    </li>
                {% endif %}
            {% endfor %}

            {% if page_obj.has_next %}
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a>
                </li>
            {% else %}
                <li class="page-item disabled">
                    <span class="page-link">下一页</span>
                </li>
            {% endif %}
        </ul>
    </nav>
{% endif %}